package com.obligatorio.persist.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;

import com.obligatorio.domain.Sector;

@Stateless
public class SectorDAOBean implements SectorDAOLocal {
	private static final Logger log = Logger.getLogger(SectorDAOBean.class
			.getName());
	@PersistenceContext(unitName = "JPA_UNIT_OBL")
	EntityManager em;

	@SuppressWarnings("unchecked")
	@Override
	public List<Sector> ObtenerTodosLosSectores() throws Exception {
		log.info("ObtenerTodosLosSectores()");
		try {
			List<Sector> res = (List<Sector>) em.createNamedQuery(
					"findAllSector").getResultList();
			return res;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Sector ObtenerUnSector(String name) throws Exception {
	log.info("ObtenerUnSector > "+name);
		try {
			return (Sector) em
					.createNamedQuery("findSectorByName", Sector.class)
					.setParameter("Nombre", name).getSingleResult();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
